package com.intelligentclass.repositories;

import com.intelligentclass.entity.Courseware;
import com.intelligentclass.entity.Exercise;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface CoursewareRepository extends JpaRepository<Courseware, Integer> {

    @Query("select c from Courseware c where c.cid = :cid")
    public List<Courseware> findAllByCid(int cid);

    public Courseware findByCid(int cid);

    @Query("select c from Courseware c where c.cid = :cid and c.parent = null ")
    public List<Courseware> findAllTopNode(@Param("cid") int cid);

    @Query("select c from Courseware c where c.cid = :cid and c.parent = :parent")
    public List<Courseware> findAllChildCourseware(@Param("cid") int cid, @Param("parent") int parent);

    @Query("select c from Courseware c where c.cid = :cid and c.name = :name")
    public Courseware findByCidAndName(@Param("cid") int cid, @Param("name") String name);

    @Query("select e from Courseware e where e.cid = :cid and e.name = :name and e.parent = :parent")
    public Courseware find(@Param("cid") int cid, @Param("name") String name, @Param("parent") int parent);
}
